#! /usr/bin/perl -w

# 打印url编码中的中文

use strict;
use Encode;
use File::Basename;

binmode(STDOUT, "utf8");
&usage unless $_ = shift;
&usage unless /(?:%[0-9a-f]{2})+/oi;

s/%([a-f\d]{2})/chr hex $1/egi;
#s/%([a-f0-9]{2})/pack("C",hex($1))/egi;

if ( $ENV{LANG} =~ /UTF-?8/i ){
    print decode("gbk", $_), "\n";
}
else {
    print $_, "\n";
}

## --------------------
sub usage {
    print basename $0. " [url_with_chinese]\n";
    exit 1;
}
